package metag

import (
	"fmt"
	"strings"
	"unicode"
)

// 字符集
type Charset string

const UTF8 Charset = "utf8"
const UTF8MB4 Charset = "utf8mb4"

type TableMetag struct {
	Name    string        //表名
	Comment string        //表备注
	Indexes []*IndexMetag //索引的元标签
	Charset Charset       //字符集
	//TODO 异步更新的方式，不异步，异步更新、异步插入
	//TODO 异步更新的批量数量
	//TODO 异步更新的延时

}

type SplitTableMetag struct {
	TableMetag
	SplitWay      SplitWay
	SplitByColumn string
}

type SplitWay string

const MINUTE SplitWay = "MINUTE"
const HOUR SplitWay = "HOUR"
const DAY SplitWay = "DAY"
const WEEK SplitWay = "WEEK"
const MONTH SplitWay = "MONTH"
const YEAR SplitWay = "YEAR"
const VALUE SplitWay = "VALUE"

func MakeSnakeCase(str string) string {
	result := ""
	for _, c := range str {
		if result == "" {
			result += strings.ToLower(fmt.Sprintf("%c", c))
		} else {
			if unicode.IsUpper(c) {
				result += strings.ToLower(fmt.Sprintf("_%c", c))
			} else {
				result += fmt.Sprintf("%c", c)
			}
		}
	}
	return result
}
